package com.example.projectcode.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.projectcode.mapper.CstuanMapper;
import com.example.projectcode.model.Cstuan;
import com.example.projectcode.service.CstuanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CstuanServiceImpl extends ServiceImpl<CstuanMapper, Cstuan> implements CstuanService {

    @Autowired
    private CstuanMapper cstuanMapper;

    @Override
    public int insertCstuan(Cstuan cstuan) {

        return baseMapper.insert(cstuan);
    }

    @Override
    public Cstuan selectOneByCStuanid(Integer cStuanid) {
        return baseMapper.selectOne(new QueryWrapper<Cstuan>().eq("C_stuanid",cStuanid));
    }

    @Override
    public List<Cstuan> selectAllByCId(Integer cId) {

        return  baseMapper.selectList(new QueryWrapper<Cstuan>().eq("C_id",cId));
    }

    @Override
    public List<Cstuan> selectAllTrueChoiceBy(Integer cId) {
        return baseMapper.selectList(
                new QueryWrapper<Cstuan>()
                        .eq("C_id",cId).eq("C_feedback","true"));
    }

    @Override
    public List<Cstuan> selectAllByStuId(Integer stuId) {
        return baseMapper.selectList(new QueryWrapper<Cstuan>().eq("Stu_id",stuId).eq("C_feedback","false"));
    }

    @Override
    public int updateCstuanByCstuanId(Integer cstuanid, String cfeedback) {
        return cstuanMapper.updateBycstuanId(cstuanid,cfeedback);
    }
}
